<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Function (computer programming)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Function_(computer_programming)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Function_computer_programming rootpage-Function_computer_programming skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Function (computer programming)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">For other uses, see <a href="Function_(disambiguation)" class="mw-redirect mw-disambig" title="Function (disambiguation)">Function</a>.</div>
<p>
</p><p>In <a href="Computer_programming" title="Computer programming">computer programming</a>, a <b>function</b> (also <b>procedure</b>, <b>method</b>, <b>subroutine</b>, <b>routine</b>, or <b>subprogram</b>) is a <b>callable unit</b><sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> of <a href="Software_logic" class="mw-redirect" title="Software logic">software logic</a> that has a well-defined <a href="Interface_(computing)" title="Interface (computing)">interface</a> and <a href="Behavior" title="Behavior">behavior</a> and can be invoked multiple times.
</p><p>Callable units provide a powerful programming tool.<sup id="cite_ref-knuth1_2-0" class="reference"><a href="#cite_note-knuth1-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> The primary purpose is to allow for the decomposition of a large and/or complicated problem into chunks that have relatively low <a href="Cognitive_load" title="Cognitive load">cognitive load</a> and to assign the chunks meaningful names (unless they are anonymous). Judicious application can reduce the cost of developing and maintaining software, while increasing its quality and reliability.<sup id="cite_ref-structprog_3-0" class="reference"><a href="#cite_note-structprog-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p><p>Callable units are present at multiple levels of <a href="Abstraction" title="Abstraction">abstraction</a> in the programming environment. For example, a <a href="Programmer" title="Programmer">programmer</a> may write a function in <a href="Source_code" title="Source code">source code</a> that is compiled to <a href="Machine_code" title="Machine code">machine code</a> that implements similar <a href="Semantics" title="Semantics">semantics</a>. There is a callable unit in the source code and an associated one in the machine code, but they are different kinds of callable units – with different implications and features.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Terminology">Terminology</h2></div>
<p>Some <a href="Programming_language" title="Programming language">programming languages</a>, such as <a href="COBOL" title="COBOL">COBOL</a> and <a href="BASIC" title="BASIC">BASIC</a>, make a distinction between functions that return a value (typically called "functions") and those that do not (typically called "subprogram", "subroutine", or "procedure"); some, such as <a href="C_(programming_language)" title="C (programming language)">C</a>, <a href="C%2B%2B" title="C++">C++</a>, and <a href="Rust_(programming_language)" title="Rust (programming language)">Rust</a>, only use the term "function" irrespective of whether they return a value or not; others, such as <a href="ALGOL_60" title="ALGOL 60">ALGOL 60</a> and <a href="PL/I" title="PL/I">PL/I</a>, only use the word <i>procedure</i>. Some <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented</a> languages, such as <a href="Java_(programming_language)" title="Java (programming language)">Java</a> and <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, refer to functions inside <a href="Class_(computer_programming)" title="Class (computer programming)">classes</a> as "<a href="Method_(computer_programming)" title="Method (computer programming)">methods</a>".
</p>
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>The idea of a callable unit was initially conceived by <a href="John_Mauchly" title="John Mauchly">John Mauchly</a> and <a href="Kathleen_Antonelli" title="Kathleen Antonelli">Kathleen Antonelli</a> during their work on <a href="ENIAC" title="ENIAC">ENIAC</a> and recorded in a January 1947 Harvard symposium on "Preparation of Problems for <a href="EDVAC" title="EDVAC">EDVAC</a>-type Machines."<sup id="cite_ref-mauchly0_4-0" class="reference"><a href="#cite_note-mauchly0-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> <a href="Maurice_Wilkes" title="Maurice Wilkes">Maurice Wilkes</a>, <a href="David_Wheeler_(British_computer_scientist)" class="mw-redirect" title="David Wheeler (British computer scientist)">David Wheeler</a>, and <a href="Stanley_Gill" title="Stanley Gill">Stanley Gill</a> are generally credited with the formal invention of this concept, which they termed a <i>closed sub-routine</i>,<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> contrasted with an <i>open subroutine</i> or <a href="Macro_(computer_science)" title="Macro (computer science)">macro</a>.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> However, <a href="Alan_Turing" title="Alan Turing">Alan Turing</a> had discussed subroutines in a paper of 1945 on design proposals for the NPL <a href="Automatic_Computing_Engine" title="Automatic Computing Engine">ACE</a>, going so far as to invent the concept of a <a href="Call_stack" title="Call stack">return address stack</a>.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p><p>The idea of a subroutine was worked out after computing machines had already existed for some time. The arithmetic and conditional jump instructions were planned ahead of time and have changed relatively little, but the special instructions used for procedure calls have changed greatly over the years. The earliest computers, such as the <a href="Manchester_Baby" title="Manchester Baby">Manchester Baby</a>, and some early microprocessors, such as the <a href="RCA_1802" title="RCA 1802">RCA 1802</a>, did not have a single subroutine call instruction. Subroutines could be implemented, but they required programmers to use the call sequence—a series of instructions—at each <a href="Call_site" title="Call site">call site</a>.
</p><p>Subroutines were implemented in <a href="Konrad_Zuse" title="Konrad Zuse">Konrad Zuse</a>'s <a href="Z4_(computer)" title="Z4 (computer)">Z4</a> in 1945.
</p><p>In 1945, <a href="Alan_Turing" title="Alan Turing">Alan Turing</a> used the terms "bury" and "unbury" as a means of calling and returning from subroutines.<sup id="cite_ref-Turing_1945_9-0" class="reference"><a href="#cite_note-Turing_1945-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Carpenter_1977_10-0" class="reference"><a href="#cite_note-Carpenter_1977-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p><p>In January 1947 John Mauchly presented general notes at 'A Symposium of Large Scale Digital Calculating Machinery'
under the joint sponsorship of Harvard University and the Bureau of Ordnance, United States Navy. Here he discusses serial and parallel operation suggesting
</p>
<style data-mw-deduplicate="TemplateStyles:r1244412712">
/* start https://en.wikipedia.org/ */
.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}
/* end https://en.wikipedia.org/ */
</style><blockquote class="templatequote"><p>...the structure of the machine need not be complicated one bit. It is possible, since all the logical characteristics essential to this procedure are available, to evolve a coding instruction for placing the subroutines in the memory at places known to the machine, and in such a way that they may easily be called into use.</p><div class="paragraphbreak" style="margin-top:0.5em"></div><p>In other words, one can designate subroutine A as division and subroutine B as complex multiplication and subroutine C as the evaluation of a standard error of a sequence of numbers, and so on through the list of subroutines needed for a particular problem. ... All these subroutines will then be stored in the machine, and all one needs to do is make a brief reference to them by number, as they are indicated in the coding.<sup id="cite_ref-mauchly0_4-1" class="reference"><a href="#cite_note-mauchly0-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup></p></blockquote>
<p><a href="Kathleen_Antonelli" title="Kathleen Antonelli">Kay McNulty</a> had worked closely with John Mauchly on the <a href="ENIAC" title="ENIAC">ENIAC</a> team and developed an idea for subroutines for the <a href="ENIAC" title="ENIAC">ENIAC</a> computer she was programming during World War II.<sup id="cite_ref-:0_11-0" class="reference"><a href="#cite_note-:0-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup> She and the other ENIAC programmers used the subroutines to help calculate missile trajectories.<sup id="cite_ref-:0_11-1" class="reference"><a href="#cite_note-:0-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
</p><p><a href="Herman_Goldstine" title="Herman Goldstine">Goldstine</a> and <a href="John_von_Neumann" title="John von Neumann">von Neumann</a> wrote a paper dated 16 August 1948 discussing the use of subroutines.<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup>
</p><p>Some very early computers and microprocessors, such as the <a href="IBM_1620" title="IBM 1620">IBM 1620</a>, the <a href="Intel_4004" title="Intel 4004">Intel 4004</a> and <a href="Intel_8008" title="Intel 8008">Intel 8008</a>, and the <a href="PIC_microcontroller" class="mw-redirect" title="PIC microcontroller">PIC microcontrollers</a>, have a single-instruction subroutine call that uses a dedicated hardware stack to store return addresses—such hardware supports only a few levels of subroutine nesting, but can support recursive subroutines. Machines before the mid-1960s—such as the <a href="UNIVAC_I" title="UNIVAC I">UNIVAC I</a>, the <a href="PDP-1" title="PDP-1">PDP-1</a>, and the <a href="IBM_1130" title="IBM 1130">IBM 1130</a>—typically use a <a href="Calling_convention" title="Calling convention">calling convention</a> which saved the instruction counter in the first memory location of the called subroutine. This allows arbitrarily deep levels of subroutine nesting but does not support recursive subroutines. The <a href="IBM_System/360" title="IBM System/360">IBM System/360</a> had a subroutine call instruction that placed the saved instruction counter value into a general-purpose register; this can be used to support arbitrarily deep subroutine nesting and recursive subroutines. The Burroughs <a href="B5000" class="mw-redirect" title="B5000">B5000</a><sup id="cite_ref-B5000-21005_13-0" class="reference"><a href="#cite_note-B5000-21005-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup> (1961) is one of the first computers to store subroutine return data on a stack.
</p><p>The DEC <a href="PDP-6" title="PDP-6">PDP-6</a><sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup> (1964) is one of the first accumulator-based machines to have a subroutine call instruction that saved the return address in a stack addressed by an accumulator or index register. The later <a href="PDP-10" title="PDP-10">PDP-10</a> (1966), <a href="PDP-11" title="PDP-11">PDP-11</a> (1970) and <a href="VAX-11" title="VAX-11">VAX-11</a> (1976) lines followed suit; this feature also supports both arbitrarily deep subroutine nesting and recursive subroutines.<sup id="cite_ref-Steele_15-0" class="reference"><a href="#cite_note-Steele-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Language_support">Language support</h3></div>
<p>In the very early assemblers, subroutine support was limited. Subroutines were not explicitly separated from each other or from the main program, and indeed the source code of a subroutine could be interspersed with that of other subprograms. Some assemblers would offer predefined <a href="Macro_(computer_science)" title="Macro (computer science)">macros</a> to generate the call and return sequences. By the 1960s, assemblers usually had much more sophisticated support for both inline and separately assembled subroutines that could be linked together.
</p><p>One of the first programming languages to support user-written subroutines and functions was <a href="Fortran#FORTRAN_II" title="Fortran">FORTRAN II</a>. The IBM FORTRAN II compiler was released in 1958. <a href="ALGOL_58" title="ALGOL 58">ALGOL 58</a> and other early programming languages also supported procedural programming.
</p>
<div class="mw-heading mw-heading3"><h3 id="Libraries">Libraries</h3></div>
<p>Even with this cumbersome approach, subroutines proved very useful. They allowed the use of the same code in many different programs. Memory was a very scarce resource on early computers, and subroutines allowed significant savings in the size of programs.
</p><p>Many early computers loaded the program instructions into memory from a <a href="Punched_tape" title="Punched tape">punched paper tape</a>. Each subroutine could then be provided by a separate piece of tape, loaded or spliced before or after the main program (or "mainline"<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup>); and the same subroutine tape could then be used by many different programs. A similar approach was used in computers that loaded program instructions from <a href="Punched_card" title="Punched card">punched cards</a>. The name <i>subroutine library</i> originally meant a library, in the literal sense, which kept indexed collections of tapes or decks of cards for collective use.
</p>
<div class="mw-heading mw-heading3"><h3 id="Return_by_indirect_jump">Return by indirect jump</h3></div>
<p>To remove the need for <a href="Self-modifying_code" title="Self-modifying code">self-modifying code</a>, computer designers eventually provided an <i><a href="Indirect_branch" title="Indirect branch">indirect jump</a></i> instruction, whose operand, instead of being the <a href="Return_statement" title="Return statement">return address</a> itself, was the location of a variable or <a href="Processor_register" title="Processor register">processor register</a> containing the return address.
</p><p>On those computers, instead of modifying the function's return jump, the calling program would store the return address in a variable so that when the function completed, it would execute an indirect jump that would direct execution to the location given by the predefined variable.
</p>
<div class="mw-heading mw-heading3"><h3 id="Jump_to_subroutine">Jump to subroutine</h3></div>
<p>Another advance was the <i>jump to subroutine</i> instruction, which combined the saving of the return address with the calling jump, thereby minimizing <a href="Computational_overhead" class="mw-redirect" title="Computational overhead">overhead</a> significantly.
</p><p>In the IBM <a href="System/360" class="mw-redirect" title="System/360">System/360</a>, for example, the branch instructions BAL or BALR, designed for procedure calling, would save the return address in a processor register specified in the instruction, by convention register 14. To return, the subroutine had only to execute an indirect branch instruction (BR) through that register. If the subroutine needed that register for some other purpose (such as calling another subroutine), it would save the register's contents to a private memory location or a register <a href="Stack_(data_structure)" class="mw-redirect" title="Stack (data structure)">stack</a>.
</p><p>In systems such as the <a href="HP_2100" title="HP 2100">HP 2100</a>, the JSB instruction would perform a similar task, except that the return address was stored in the memory location that was the target of the branch. Execution of the procedure would actually begin at the next memory location. In the HP 2100 assembly language, one would write, for example
</p>
<div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre>...
JSB MYSUB (Calls subroutine MYSUB.)
BB ... (Will return here after MYSUB is done.)
</pre></div>
<p>to call a subroutine called MYSUB from the main program. The subroutine would be coded as
</p>
<div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre>MYSUB NOP (Storage for MYSUB's return address.)
AA ... (Start of MYSUB's body.)
...
JMP MYSUB,I (Returns to the calling program.)
</pre></div>
<p>The JSB instruction placed the address of the NEXT instruction (namely, BB) into the location specified as its operand (namely, MYSUB), and then branched to the NEXT location after that (namely, AA = MYSUB + 1). The subroutine could then return to the main program by executing the indirect jump JMP MYSUB, I which branched to the location stored at location MYSUB.
</p><p>Compilers for Fortran and other languages could easily make use of these instructions when available. This approach supported multiple levels of calls; however, since the return address, parameters, and return values of a subroutine were assigned fixed memory locations, it did not allow for recursive calls.
</p><p>Incidentally, a similar method was used by <a href="Lotus_1-2-3" title="Lotus 1-2-3">Lotus 1-2-3</a>, in the early 1980s, to discover the recalculation dependencies in a spreadsheet. Namely, a location was reserved in each cell to store the <i>return</i> address. Since <a href="Circular_reference" title="Circular reference">circular references</a> are not allowed for natural recalculation order, this allows a tree walk without reserving space for a stack in memory, which was very limited on small computers such as the <a href="IBM_PC" class="mw-redirect" title="IBM PC">IBM PC</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Call_stack">Call stack</h3></div>
<p>Most modern implementations of a function call use a <a href="Call_stack" title="Call stack">call stack</a>, a special case of the <a href="Stack_(data_structure)" class="mw-redirect" title="Stack (data structure)">stack data structure</a>, to implement function calls and returns. Each procedure call creates a new entry, called a <i>stack frame</i>, at the top of the stack; when the procedure returns, its stack frame is deleted from the stack, and its space may be used for other procedure calls. Each stack frame contains the <i>private data</i> of the corresponding call, which typically includes the procedure's parameters and internal variables, and the return address.
</p><p>The call sequence can be implemented by a sequence of ordinary instructions (an approach still used in <a href="Reduced_instruction_set_computing" class="mw-redirect" title="Reduced instruction set computing">reduced instruction set computing</a> (RISC) and <a href="Very_long_instruction_word" title="Very long instruction word">very long instruction word</a> (VLIW) architectures), but many traditional machines designed since the late 1960s have included special instructions for that purpose.
</p><p>The call stack is usually implemented as a contiguous area of memory. It is an arbitrary design choice whether the bottom of the stack is the lowest or highest address within this area, so that the stack may grow forwards or backwards in memory; however, many architectures chose the latter.
</p><p>Some designs, notably some <a href="Forth_(programming_language)" title="Forth (programming language)">Forth</a> implementations, used two separate stacks, one mainly for control information (like return addresses and loop counters) and the other for data. The former was, or worked like, a call stack and was only indirectly accessible to the programmer through other language constructs while the latter was more directly accessible.
</p><p>When stack-based procedure calls were first introduced, an important motivation was to save precious memory. With this scheme, the compiler does not have to reserve separate space in memory for the private data (parameters, return address, and local variables) of each procedure. At any moment, the stack contains only the private data of the calls that are currently <i>active</i> (namely, which have been called but haven't returned yet). Because of the ways in which programs were usually assembled from libraries, it was (and still is) not uncommon to find programs that include thousands of functions, of which only a handful are active at any given moment. For such programs, the call stack mechanism could save significant amounts of memory. Indeed, the call stack mechanism can be viewed as the earliest and simplest method for <a href="Garbage_collection_(computer_science)" title="Garbage collection (computer science)">automatic memory management</a>.
</p><p>However, another advantage of the call stack method is that it allows <a href="Recursion_(computer_science)" title="Recursion (computer science)">recursive function calls</a>, since each nested call to the same procedure gets a separate instance of its private data.
</p><p>In a <a href="Thread_(computer_science)" class="mw-redirect" title="Thread (computer science)">multi-threaded</a> environment, there is generally more than one stack.<sup id="cite_ref-ButtlarFarrellNichols1996_17-0" class="reference"><a href="#cite_note-ButtlarFarrellNichols1996-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup> An environment that fully supports <a href="Coroutine" title="Coroutine">coroutines</a> or <a href="Lazy_evaluation" title="Lazy evaluation">lazy evaluation</a> may use data structures other than stacks to store their activation records.
</p>
<div class="mw-heading mw-heading4"><h4 id="Delayed_stacking">Delayed stacking </h4></div>
<p>One disadvantage of the call stack mechanism is the increased cost of a procedure call and its matching return. The extra cost includes incrementing and decrementing the stack pointer (and, in some architectures, checking for <a href="Stack_overflow" title="Stack overflow">stack overflow</a>), and accessing the local variables and parameters by frame-relative addresses, instead of absolute addresses. The cost may be realized in increased execution time, or increased processor complexity, or both.
</p><p>This overhead is most obvious and objectionable in <i>leaf procedures</i> or <i><a href="Leaf_function" class="mw-redirect" title="Leaf function">leaf functions</a></i>, which return without making any procedure calls themselves.<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span class="cite-bracket">[</span>19<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">[</span>20<span class="cite-bracket">]</span></a></sup> To reduce that overhead, many modern compilers try to delay the use of a call stack until it is really needed. For example, the call of a procedure <i>P</i> may store the return address and parameters of the called procedure in certain processor registers, and transfer control to the procedure's body by a simple jump. If the procedure <i>P</i> returns without making any other call, the call stack is not used at all. If <i>P</i> needs to call another procedure <i>Q</i>, it will then use the call stack to save the contents of any registers (such as the return address) that will be needed after <i>Q</i> returns.
</p>
<div class="mw-heading mw-heading2"><h2 id="Features">Features</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>In general, a callable unit is a list of instructions that, starting at the first instruction, executes sequentially except as directed via its internal logic. It can be invoked (called) many times during the <a href="Execution_(computing)" title="Execution (computing)">execution</a> of a program. Execution continues at the next instruction after the call instruction when it <a href="Return_statement" title="Return statement">returns</a> control.
</p>
<div class="mw-heading mw-heading2"><h2 id="Implementations">Implementations</h2></div>
<p>The features of <a href="Implementation" title="Implementation">implementations</a> of callable units evolved over time and varies by context.
This section describes features of the various common implementations.
</p>
<div class="mw-heading mw-heading3"><h3 id="General_characteristics">General characteristics</h3></div>
<p>Most modern programming languages provide features to define and call functions, including <a href="Syntax_(programming_languages)" title="Syntax (programming languages)">syntax</a> for accessing such features, including:
</p>
<ul><li>Delimit the implementation of a function from the rest of the program</li>
<li>Assign an <a href="Identifier" title="Identifier">identifier</a>, name, to a function</li>
<li>Define <a href="Formal_parameters" class="mw-redirect" title="Formal parameters">formal parameters</a> with a name and <a href="Data_type" title="Data type">data type</a> for each</li>
<li>Assign a <a href="Data_type" title="Data type">data type</a> to the return value, if any</li>
<li>Specify a return value in the function body</li>
<li>Call a function</li>
<li>Provide <a href="Actual_parameters" class="mw-redirect" title="Actual parameters">actual parameters</a> that correspond to a called function's formal parameters</li>
<li><a href="Return_statement" title="Return statement">Return</a> control to the caller at the point of call</li>
<li>Consume the return value in the caller</li>
<li>Dispose of the values returned by a call</li>
<li>Provide a private <a href="Scope_(computer_science)" title="Scope (computer science)">naming scope</a> for variables</li>
<li>Identify variables outside the function that are accessible within it</li>
<li>Propagate an <a href="Exception_handling" title="Exception handling">exceptional condition</a> out of a function and to handle it in the calling context</li>
<li>Package functions into a container such as <a href="Modular_programming" title="Modular programming">module</a>, <a href="Library_(computing)" title="Library (computing)">library</a>, <a href="Object_(computer_science)" title="Object (computer science)">object</a>, or <a href="Class_(computer_programming)" title="Class (computer programming)">class</a></li></ul>
<div class="mw-heading mw-heading3"><h3 id="Naming">Naming</h3></div>
<p>Some languages, such as <a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>, <a href="Fortran" title="Fortran">Fortran</a>, <a href="Ada_(programming_language)" title="Ada (programming language)">Ada</a> and many <a href="Dialect_(computing)" class="mw-redirect" title="Dialect (computing)">dialects</a> of <a href="BASIC" title="BASIC">BASIC</a>, use a different name for a callable unit that returns a value (<i>function</i> or <i>subprogram</i>) vs. one that does not (<i>subroutine</i> or <i>procedure</i>).
Other languages, such as <a href="C_(programming_language)" title="C (programming language)">C</a>, <a href="C%2B%2B" title="C++">C++</a>, <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> and <a href="Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a>, use only one name for a callable unit, <i>function</i>. The C-family languages use the keyword <code>void</code> to indicate no return value.
</p>
<div class="mw-heading mw-heading3"><h3 id="Call_syntax">Call syntax</h3></div>
<p>If declared to return a value, a call can be embedded in an <a href="Expression_(programming)" class="mw-redirect" title="Expression (programming)">expression</a> in order to consume the return value. For example, a square root callable unit might be called like <code>y = sqrt(x)</code>.
</p><p>A callable unit that does not return a value is called as a stand-alone <a href="Statement_(computer_science)" title="Statement (computer science)">statement</a> like <code>print("hello")</code>. This syntax can also be used for a callable unit that returns a value, but the return value will be ignored.
</p><p>Some older languages require a keyword for calls that do not consume a return value, like <code>CALL print("hello")</code>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Parameters">Parameters</h3></div>
<p>Most implementations, especially in modern languages, support <a href="Parameter_(computer_science)" class="mw-redirect" title="Parameter (computer science)">parameters</a> which the callable declares as <i>formal parameters</i>. A caller passes <i>actual parameters</i>, a.k.a. <i>arguments</i>, to match. Different programming languages provide different conventions for passing arguments.
</p>
<table class="wikitable">
<tbody><tr>
<th>Convention</th>
<th>Description</th>
<th>Used in
</th></tr>
<tr>
<td><a href="Call_by_value" class="mw-redirect" title="Call by value">by value</a></td>
<td>A copy of the argument is passed</td>
<td>Default in most Algol-like languages after <a href="Algol_60" class="mw-redirect" title="Algol 60">Algol 60</a>, such as Pascal, Delphi, Simula, CPL, PL/M, Modula, Oberon, Ada, and many others including C, C++ and Java
</td></tr>
<tr>
<td><a href="Call_by_reference" class="mw-redirect" title="Call by reference">by reference</a></td>
<td>A reference to the argument is passed; typically its address</td>
<td>Selectable in most Algol-like languages after <a href="Algol_60" class="mw-redirect" title="Algol 60">Algol 60</a>, such as Algol 68, Pascal, Delphi, Simula, CPL, PL/M, Modula, Oberon, Ada, and many others including C++, Fortran, PL/I
</td></tr>
<tr>
<td><a href="Call_by_result" class="mw-redirect" title="Call by result">by result</a></td>
<td>The value computed during the call is copied to the argument on return</td>
<td>Ada OUT parameters
</td></tr>
<tr>
<td><a href="Call_by_value-result" class="mw-redirect" title="Call by value-result">by value-result</a></td>
<td>A copy of the argument is passed in and the value computed during the call is copied to the argument on return</td>
<td>Algol, <a href="Swift_(programming_language)" title="Swift (programming language)">Swift</a> in-out parameters
</td></tr>
<tr>
<td><a href="Call_by_name" class="mw-redirect" title="Call by name">by name</a></td>
<td>Like a macro – replace the parameters with the unevaluated argument expressions, then evaluate the argument in the context of the caller every time that the callable uses the parameter</td>
<td>Algol, <a href="Scala_(programming_language)" title="Scala (programming language)">Scala</a>
</td></tr>
<tr>
<td>by constant value</td>
<td>Like by-value except that the parameter is treated as a constant</td>
<td>PL/I NONASSIGNABLE parameters, Ada IN parameters
</td></tr></tbody></table>
<div class="mw-heading mw-heading3"><h3 id="Return_value">Return value</h3></div>
<p>In some languages, such as BASIC, a callable has different syntax (i.e. keyword) for a callable that returns a value vs. one that does not.
In other languages, the syntax is the same regardless.
In some of these languages an extra keyword is used to declare no return value; for example <code>void</code> in C, C++ and C#.
In some languages, such as Python, the difference is whether the body contains a return statement with a value, and a particular callable may return with or without a value based on control flow.
</p>
<div class="mw-heading mw-heading3"><h3 id="Side_effects">Side effects</h3></div>
<p>In many contexts, a callable may have <a href="Side-effect_(computer_science)" class="mw-redirect" title="Side-effect (computer science)">side effect</a> behavior such as modifying passed or global data, reading from or writing to a <a href="Peripheral_device" class="mw-redirect" title="Peripheral device">peripheral device</a>, accessing a <a href="Computer_file" title="Computer file">file</a>, halting the program or the machine, or temporarily pausing program execution.
</p><p>Side effects are considered undesirable by <a href="Robert_C._Martin" title="Robert C. Martin">Robert C. Martin</a>, who is known for promoting design principles. Martin argues that side effects can result in <a href="Sequential_coupling" title="Sequential coupling">temporal coupling</a> or order dependencies.<sup id="cite_ref-clean_code_21-0" class="reference"><a href="#cite_note-clean_code-21"><span class="cite-bracket">[</span>21<span class="cite-bracket">]</span></a></sup>
</p><p>In strictly <a href="Functional_programming" title="Functional programming">functional programming</a> languages such as <a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a>, a function can have no <a href="Side_effect_(computer_science)" title="Side effect (computer science)">side effects</a>, which means it cannot change the state of the program. Functions always return the same result for the same input. Such languages typically only support functions that return a value, since there is no value in a function that has neither return value nor side effect.
</p><p>
</p>
<div class="mw-heading mw-heading3"><h3 id="Local_variables">Local variables</h3></div>
<p>Most contexts support <i>local variables</i> – <a href="Virtual_memory" title="Virtual memory">memory</a> owned by a callable to hold intermediate values. These variables are typically stored in the call's <i>activation record</i> on the <a href="Call_stack" title="Call stack">call stack</a> along with other information such as the <a href="Return_address_(computing)" class="mw-redirect" title="Return address (computing)">return address</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Nested_call_–_recursion">Nested call – recursion</h3></div>
<p>If supported by the language, a callable may call itself, causing its execution to suspend while another <i>nested</i> execution of the same callable executes. <a href="Recursion_(computer_science)" title="Recursion (computer science)">Recursion</a> is a useful means to simplify some complex algorithms and break down complex problems. Recursive languages provide a new copy of local variables on each call. If the programmer desires the recursive callable to use the same variables instead of using locals, they typically declare them in a shared context such static or global.
</p><p>Languages going back to <a href="ALGOL" title="ALGOL">ALGOL</a>, <a href="PL/I" title="PL/I">PL/I</a> and <a href="C_(programming_language)" title="C (programming language)">C</a> and modern languages, almost invariably use a call stack, usually supported by the instruction sets to provide an activation record for each call. That way, a nested call can modify its local variables without affecting any of the suspended calls variables.
</p><p>Recursion allows direct implementation of functionality defined by <a href="Mathematical_induction" title="Mathematical induction">mathematical induction</a> and recursive <a href="Divide_and_conquer_algorithm" class="mw-redirect" title="Divide and conquer algorithm">divide and conquer algorithms</a>. Here is an example of a recursive function in C/C++ to find <a href="Fibonacci_sequence" title="Fibonacci sequence">Fibonacci numbers</a>:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">int</span><span class="w"> </span><span class="nf">Fib</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">n</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">n</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">Fib</span><span class="p">(</span><span class="n">n</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Fib</span><span class="p">(</span><span class="n">n</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>Early languages like <a href="Fortran" title="Fortran">Fortran</a> did not initially support recursion because only one set of variables and return address were allocated for each callable.<sup id="cite_ref-BöckenhauerKommUnger2018_22-0" class="reference"><a href="#cite_note-BöckenhauerKommUnger2018-22"><span class="cite-bracket">[</span>22<span class="cite-bracket">]</span></a></sup> Early computer instruction sets made storing return addresses and variables on a stack difficult. Machines with <a href="Index_registers" class="mw-redirect" title="Index registers">index registers</a> or <a href="General-purpose_registers" class="mw-redirect" title="General-purpose registers">general-purpose registers</a>, e.g., <a href="CDC_6000_series" title="CDC 6000 series">CDC 6000 series</a>, <a href="PDP-6" title="PDP-6">PDP-6</a>, <a href="GE_635" class="mw-redirect" title="GE 635">GE 635</a>, <a href="System/360" class="mw-redirect" title="System/360">System/360</a>, <a href="UNIVAC_1100_series" class="mw-redirect" title="UNIVAC 1100 series">UNIVAC 1100 series</a>, could use one of those registers as a <a href="Stack_pointer" class="mw-redirect" title="Stack pointer">stack pointer</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Nested_scope">Nested scope</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Nested_function" title="Nested function">Nested function</a></div>
<p>Some languages, e.g., <a href="Ada_(programming_language)" title="Ada (programming language)">Ada</a>, <a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>, <a href="PL/I" title="PL/I">PL/I</a>, <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, support declaring and defining a function inside, e.g., a function body, such that the name of the inner is only visible within the body of the outer.
</p><p>
A simple example in Pascal:</p><div class="mw-highlight mw-highlight-lang-pascal mw-content-ltr" dir="ltr"><pre><span class="k">function</span><span class="w"> </span><span class="nf">E</span><span class="p">(</span><span class="n">x</span><span class="o">:</span><span class="w"> </span><span class="kt">real</span><span class="p">)</span><span class="o">:</span><span class="w"> </span><span class="kt">real</span><span class="o">;</span>
<span class="w"> </span><span class="k">function</span><span class="w"> </span><span class="nf">F</span><span class="p">(</span><span class="n">y</span><span class="o">:</span><span class="w"> </span><span class="kt">real</span><span class="p">)</span><span class="o">:</span><span class="w"> </span><span class="kt">real</span><span class="o">;</span>
<span class="w"> </span><span class="k">begin</span>
<span class="w"> </span><span class="n">F</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">y</span>
<span class="w"> </span><span class="k">end</span><span class="o">;</span>
<span class="k">begin</span>
<span class="w"> </span><span class="n">E</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="n">F</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">F</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="k">end</span><span class="o">;</span>
</pre></div><p>The function <code>F</code> is nested within <code>E</code>. Note that <code>E</code>'s parameter <code>x</code> is also visible in <code>F</code> (as <code>F</code> is a part of <code>E</code>) while both <code>x</code> and <code>y</code> are invisible outside <code>E</code> and <code>F</code> respectively.
</p><div class="mw-heading mw-heading3"><h3 id="Reentrancy">Reentrancy</h3></div>
<p>If a callable can be executed properly even when another execution of the same callable is already in progress, that callable is said to be <i><a href="Reentrant_(subroutine)" class="mw-redirect" title="Reentrant (subroutine)">reentrant</a></i>. A reentrant callable is also useful in <a href="Thread_(computer_science)" class="mw-redirect" title="Thread (computer science)">multi-threaded</a> situations since multiple threads can call the same callable without fear of interfering with each other. In the <a href="IBM" title="IBM">IBM</a> <a href="CICS" title="CICS">CICS</a> <a href="Transaction_processing_system" title="Transaction processing system">transaction processing system</a>, <i>quasi-reentrant</i> was a slightly less restrictive, but similar, requirement for application programs that were shared by many threads.
</p>
<div class="mw-heading mw-heading3"><h3 id="Overloading">Overloading</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Function_overloading" title="Function overloading">Function overloading</a></div>
<p>Some languages support <i>overloading</i> – allow multiple callables with the same name in the same scope, but operating on different types of input. Consider the square root function applied to real number, complex number and matrix input. The algorithm for each type of input is different, and the return value may have a different type. By writing three separate callables with the same name. i.e. <i>sqrt</i>, the resulting code may be easier to write and to maintain since each one has a name that is relatively easy to understand and to remember instead of giving longer and more complicated names like <i>sqrt_real</i>, <i>sqrt_complex</i>, <i>qrt_matrix</i>.
</p><p>Overloading is supported in many languages that support <a href="Strong_typing" class="mw-redirect" title="Strong typing">strong typing</a>. Often the compiler selects the overload to call based on the type of the input arguments or it fails if the input arguments do not select an overload. Older and weakly-typed languages generally do not support overloading.
</p><p>Here is an example of overloading in <a href="C%2B%2B" title="C++">C++</a>, two functions <code>Area</code> that accept different types:
</p>
<div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span class="c1">// returns the area of a rectangle defined by height and width</span>
<span class="kt">double</span><span class="w"> </span><span class="nf">Area</span><span class="p">(</span><span class="kt">double</span><span class="w"> </span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">w</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">w</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="c1">// returns the area of a circle defined by radius</span>
<span class="kt">double</span><span class="w"> </span><span class="nf">Area</span><span class="p">(</span><span class="kt">double</span><span class="w"> </span><span class="n">r</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mf">3.14</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>
<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">rectangle_area</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Area</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">);</span>
<span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">circle_area</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Area</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>PL/I has the <code>GENERIC</code> attribute to define a generic name for a set of entry references called with different types of arguments. Example:
</p>
<pre>DECLARE gen_name GENERIC(
name WHEN(FIXED BINARY),
flame WHEN(FLOAT),
pathname OTHERWISE);</pre>
<p>Multiple argument definitions may be specified for each entry. A call to "gen_name" will result in a call to "name" when the argument is FIXED BINARY, "flame" when FLOAT", etc. If the argument matches none of the choices "pathname" will be called.
</p>
<div class="mw-heading mw-heading3"><h3 id="Closure">Closure</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Closure_(computer_science)" class="mw-redirect" title="Closure (computer science)">Closure (computer science)</a></div>
<p>A <i><a href="Closure_(computer_science)" class="mw-redirect" title="Closure (computer science)">closure</a></i> is a callable plus values of some of its variables captured from the environment in which it was created. Closures were a notable feature of the Lisp programming language, introduced by <a href="John_McCarthy_(computer_scientist)" title="John McCarthy (computer scientist)">John McCarthy</a>. Depending on the implementation, closures can serve as a mechanism for side-effects.
</p>
<div class="mw-heading mw-heading3"><h3 id="Exception_reporting">Exception reporting</h3></div>
<p>Besides its <a href="Happy_path" title="Happy path">happy path</a> behavior, a callable may need to inform the caller about an <a href="Exception_(computer_science)" class="mw-redirect" title="Exception (computer science)">exceptional</a> condition that occurred during its execution.
</p><p>Most modern languages support exceptions which allows for exceptional control flow that pops the call stack until an exception handler is found to handle the condition.
</p><p>Languages that do not support exceptions can use the return value to indicate success or failure of a call. Another approach is to use a well-known location like a global variable for success indication. A callable writes the value and the caller reads it after a call.
</p><p>In the <a href="IBM_System/360" title="IBM System/360">IBM System/360</a>, where return code was expected from a subroutine, the return value was often designed to be a multiple of 4—so that it could be used as a direct <a href="Branch_table" title="Branch table">branch table</a> index into a branch table often located immediately after the call instruction to avoid extra conditional tests, further improving efficiency. In the <a href="System/360" class="mw-redirect" title="System/360">System/360</a> <a href="Assembly_language" title="Assembly language">assembly language</a>, one would write, for example:
</p>
<div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre> BAL 14, SUBRTN01 go to a subroutine, storing return address in R14
B TABLE(15) use returned value in reg 15 to index the branch table,
* branching to the appropriate branch instr.
TABLE B OK return code =00 GOOD }
B BAD return code =04 Invalid input } Branch table
B ERROR return code =08 Unexpected condition }
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Call_overhead">Call overhead</h3></div>
<p>A call has runtime <a href="Computational_overhead" class="mw-redirect" title="Computational overhead">overhead</a>, which may include but is not limited to:
</p>
<ul><li>Allocating and reclaiming call stack storage</li>
<li>Saving and restoring processor registers</li>
<li>Copying input variables</li>
<li>Copying values after the call into the caller's context</li>
<li>Automatic testing of the return code</li>
<li>Handling of exceptions</li>
<li>Dispatching such as for a virtual method in an object-oriented language</li></ul>
<p>Various techniques are employed to minimize the runtime cost of calls.
</p>
<div class="mw-heading mw-heading4"><h4 id="Compiler_optimization">Compiler optimization</h4></div>
<p>Some optimizations for minimizing call overhead may seem straight forward, but cannot be used if the callable has side effects. For example, in the expression <code>(f(x)-1)/(f(x)+1)</code>, the function <code>f</code> cannot be called only once with its value used two times since the two calls may return different results. Moreover, in the few languages which define the order of evaluation of the division operator's operands, the value of <code>x</code> must be fetched again before the second call, since the first call may have changed it. Determining whether a callable has a side effect is difficult – indeed, <a href="Undecidable_problem" title="Undecidable problem">undecidable</a> by virtue of <a href="Rice's_theorem" title="Rice's theorem">Rice's theorem</a>. So, while this optimization is safe in a purely functional programming language, a compiler for a language not limited to functional typically assumes the worst case, that every callable may have side effects.
</p>
<div class="mw-heading mw-heading4"><h4 id="Inlining">Inlining</h4></div>
<p><a href="Inline_expansion" title="Inline expansion">Inlining</a> eliminates calls for particular callables. The compiler replaces each call with the compiled code of the callable. Not only does this avoid the call overhead, but it also allows the <a href="Compiler" title="Compiler">compiler</a> to <a href="Code_optimization" class="mw-redirect" title="Code optimization">optimize</a> code of the caller more effectively by taking into account the context and arguments at that call. Inlining, however, usually increases the compiled code size, except when only called once or the body is very short, like one line.
</p>
<div class="mw-heading mw-heading3"><h3 id="Sharing">Sharing</h3></div>
<p>Callables can be defined within a program, or separately in a <a href="Library_(computing)" title="Library (computing)">library</a> that can be used by multiple programs.
</p>
<div class="mw-heading mw-heading3"><h3 id="Inter-operability">Inter-operability</h3></div>
<p>A <a href="Compiler" title="Compiler">compiler</a> translates call and return statements into machine instructions according to a well-defined <a href="Calling_convention" title="Calling convention">calling convention</a>. For code compiled by the same or a compatible compiler, functions can be compiled separately from the programs that call them. The instruction sequences corresponding to call and return statements are called the procedure's <a href="Function_prologue" class="mw-redirect" title="Function prologue">prologue and epilogue</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Built-in_functions">Built-in functions</h3></div>
<p>
</p>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Intrinsic_function" title="Intrinsic function">Intrinsic function</a></div>
<p>A <i>built-in function</i>, or <i>builtin function</i>, or <i>intrinsic function</i>, is a function for which the compiler generates code at <a href="Compile_time" title="Compile time">compile time</a> or provides in a way other than for other functions.<sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span class="cite-bracket">[</span>23<span class="cite-bracket">]</span></a></sup> A built-in function does not need to be defined like other functions since it is <i>built in</i> to the programming language.<sup id="cite_ref-24" class="reference"><a href="#cite_note-24"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Programming">Programming</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Trade-offs">Trade-offs</h3></div>
<div class="mw-heading mw-heading4"><h4 id="Advantages">Advantages</h4></div>
<p>Advantages of breaking a program into functions include:
</p>
<ul><li><a href="Decomposition_(computer_science)" title="Decomposition (computer science)">Decomposing</a> a complex programming task into simpler steps: this is one of the two main tools of <a href="Structured_programming" title="Structured programming">structured programming</a>, along with <a href="Data_structure" title="Data structure">data structures</a></li>
<li>Reducing <a href="Duplicate_code" title="Duplicate code">duplicate code</a> within a program</li>
<li>Enabling <a href="Code_reuse" title="Code reuse">reuse of code</a> across multiple programs</li>
<li>Dividing a large programming task among various programmers or various stages of a project</li>
<li><a href="Information_hiding" title="Information hiding">Hiding implementation details</a> from users of the function</li>
<li>Improving readability of code by replacing a block of code with a function call where a <a rel="nofollow" class="external text" href="https://books.google.com/books?id=_i6bDeoCQzsC&pg=PA39&dq=descriptive+function+name">descriptive</a> function name serves to describe the block of code. This makes the calling code concise and readable even if the function is not meant to be reused.</li>
<li>Improving <a href="Traceability#Software" title="Traceability">traceability</a> (i.e. most languages offer ways to obtain the call trace which includes the names of the involved functions and perhaps even more information such as file names and line numbers); by not decomposing the code into functions, debugging would be severely impaired</li></ul>
<div class="mw-heading mw-heading4"><h4 id="Disadvantages">Disadvantages</h4></div>
<p>Compared to using in-line code, invoking a function imposes some <a href="Computational_overhead" class="mw-redirect" title="Computational overhead">computational overhead</a> in the call mechanism.
</p><p>A function typically requires standard <a href="Housekeeping_(computing)" title="Housekeeping (computing)">housekeeping</a> code – both at the entry to, and exit from, the function (<a href="Function_prologue" class="mw-redirect" title="Function prologue">function prologue and epilogue</a> – usually saving <a href="General_purpose_register" class="mw-redirect" title="General purpose register">general purpose registers</a> and return address as a minimum).
</p>
<div class="mw-heading mw-heading3"><h3 id="Conventions">Conventions</h3></div>
<p>Many programming conventions have been developed regarding callables.
</p><p>With respect to naming, many developers name a callable with a phrase starting with a <a href="Verb" title="Verb">verb</a> when it does a certain task, with an <a href="Adjective" title="Adjective">adjective</a> when it makes an inquiry, and with a <a href="Noun" title="Noun">noun</a> when it is used to substitute variables.
</p><p>Some programmers suggest that a callable should perform exactly one task, and if it performs more than one task, it should be split up into multiple callables. They argue that callables are key components in <a href="Software_maintenance" title="Software maintenance">software maintenance</a>, and their roles in the program must remain distinct.
</p><p>Proponents of <a href="Modular_programming" title="Modular programming">modular programming</a> advocate that each callable should have minimal dependency on the rest of the <a href="Codebase" title="Codebase">codebase</a>. For example, the use of <a href="Global_variable" title="Global variable">global variables</a> is generally deemed unwise, because it adds coupling between all callables that use the global variables. If such coupling is not necessary, they advise to <a href="Code_refactoring" title="Code refactoring">refactor</a> callables to accept passed <a href="Parameter_(computer_programming)" title="Parameter (computer programming)">parameters</a> instead.
</p>
<div class="mw-heading mw-heading2"><h2 id="Examples">Examples</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Early_BASIC">Early BASIC</h3></div>
<p>Early BASIC variants require each line to have a unique number (<a href="Line_number" title="Line number">line number</a>) that orders the lines for execution, provides no separation of the code that is callable, no mechanism for passing arguments or to return a value and all variables are global. It provides the command <code>GOSUB</code> where <i>sub</i> is short for <i>sub procedure</i>, <i>subprocedure</i> or <i>subroutine</i>. Control jumps to the specified line number and then continues on the next line on return.
</p>
<div class="mw-highlight mw-highlight-lang-basic mw-content-ltr" dir="ltr"><pre><span class="nl">10</span><span class="w"> </span><span class="c1">REM A BASIC PROGRAM</span>
<span class="nl">20</span><span class="w"> </span><span class="kr">GOSUB</span><span class="w"> </span><span class="nl">100</span>
<span class="nl">30</span><span class="w"> </span><span class="kr">GOTO</span><span class="w"> </span><span class="nl">20</span>
<span class="nl">100</span><span class="w"> </span><span class="kr">INPUT</span><span class="w"> </span><span class="err">“</span><span class="vg">GIVE</span><span class="w"> </span><span class="vg">ME</span><span class="w"> </span><span class="vg">A</span><span class="w"> </span><span class="vg">NUMBER</span><span class="err">”</span><span class="p">;</span><span class="w"> </span><span class="vg">N</span>
<span class="nl">110</span><span class="w"> </span><span class="kr">PRINT</span><span class="w"> </span><span class="err">“</span><span class="vg">THE</span><span class="w"> </span><span class="vg">SQUARE</span><span class="w"> </span><span class="vg">ROOT</span><span class="w"> </span><span class="vg">OF</span><span class="err">”</span><span class="p">;</span><span class="w"> </span><span class="vg">N</span><span class="p">;</span><span class="w"> </span>
<span class="nl">120</span><span class="w"> </span><span class="kr">PRINT</span><span class="w"> </span><span class="err">“</span><span class="k">IS</span><span class="err">”</span><span class="p">;</span><span class="w"> </span><span class="vg">SQRT</span><span class="p">(</span><span class="vg">N</span><span class="p">)</span>
<span class="nl">130</span><span class="w"> </span><span class="kr">RETURN</span>
</pre></div>
<p>This code repeatedly asks the user to enter a number and reports the square root of the value. Lines 100-130 are the callable.
</p>
<div class="mw-heading mw-heading3"><h3 id="Small_Basic">Small Basic</h3></div>
<p>In <a href="Microsoft_Small_Basic" title="Microsoft Small Basic">Microsoft Small Basic</a>, targeted to the student first learning how to program in a text-based language, a callable unit is called a <i>subroutine</i>.
The <code>Sub</code> keyword denotes the start of a subroutine and is followed by a name identifier. Subsequent lines are the body which ends with the <code>EndSub</code> keyword.
<sup id="cite_ref-25" class="reference"><a href="#cite_note-25"><span class="cite-bracket">[</span>25<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span class="k">Sub</span><span class="w"> </span><span class="nf">SayHello</span>
<span class="w"> </span><span class="n">TextWindow</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">"Hello!"</span><span class="p">)</span>
<span class="n">EndSub</span>
</pre></div>
<p>This can be called as <code>SayHello()</code>.
<sup id="cite_ref-26" class="reference"><a href="#cite_note-26"><span class="cite-bracket">[</span>26<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Visual_Basic">Visual Basic</h3></div>
<p>In later versions of <a href="Visual_Basic" title="Visual Basic">Visual Basic</a> (VB), including the <a href="Visual_Basic_(.NET)" title="Visual Basic (.NET)">latest product line</a> and <a href="Visual_Basic_(classic)" title="Visual Basic (classic)">VB6</a>, the term <i>procedure</i> is used for the callable unit concept. The keyword <code>Sub</code> is used to return no value and <code>Function</code> to return a value. When used in the context of a class, a procedure is a method.
<sup id="cite_ref-27" class="reference"><a href="#cite_note-27"><span class="cite-bracket">[</span>27<span class="cite-bracket">]</span></a></sup>
</p><p>Each parameter has a <a href="Data_type" title="Data type">data type</a> that can be specified, but if not, defaults to <code>Object</code> for later versions based on <a href=".NET" title=".NET">.NET</a> and <a href="Variant_type" class="mw-redirect" title="Variant type">variant</a> for <a href="Visual_Basic_6" class="mw-redirect" title="Visual Basic 6">VB6</a>.<sup id="cite_ref-28" class="reference"><a href="#cite_note-28"><span class="cite-bracket">[</span>28<span class="cite-bracket">]</span></a></sup>
</p><p>VB supports parameter passing conventions <a href="Call_by_value" class="mw-redirect" title="Call by value">by value</a> and <a href="Call_by_reference" class="mw-redirect" title="Call by reference">by reference</a> via the keywords <code>ByVal</code> and <code>ByRef</code>, respectively.
Unless <code>ByRef</code> is specified, an argument is passed <code>ByVal</code>. Therefore, <code>ByVal</code> is rarely explicitly specified.
</p><p>For a simple type like a number these conventions are relatively clear. Passing <code>ByRef</code> allows the procedure to modify the passed variable whereas passing <code>ByVal</code> does not. For an object, semantics can confuse programmers since an object is always treated as a reference. Passing an object <code>ByVal</code> copies the reference; not the state of the object. The called procedure can modify the state of the object via its methods yet cannot modify the object reference of the actual parameter.
</p>
<div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span class="k">Sub</span><span class="w"> </span><span class="nf">DoSomething</span><span class="p">()</span>
<span class="w"> </span><span class="c">' Some Code Here</span>
<span class="k">End</span><span class="w"> </span><span class="k">Sub</span>
</pre></div>
<p>The does not return a value and has to be called stand-alone, like <code>DoSomething</code>
</p>
<div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span class="k">Function</span><span class="w"> </span><span class="nf">GiveMeFive</span><span class="p">()</span><span class="w"> </span><span class="ow">as</span><span class="w"> </span><span class="kt">Integer</span>
<span class="w"> </span><span class="n">GiveMeFive</span><span class="o">=</span><span class="w"> </span><span class="mi">5</span>
<span class="k">End</span><span class="w"> </span><span class="k">Function</span>
</pre></div>
<p>This returns the value 5, and a call can be part of an expression like <code>y = x + GiveMeFive()</code>
</p>
<div class="mw-highlight mw-highlight-lang-vbnet mw-content-ltr" dir="ltr"><pre><span class="k">Sub</span><span class="w"> </span><span class="nf">AddTwo</span><span class="p">(</span><span class="k">ByRef</span><span class="w"> </span><span class="n">intValue</span><span class="w"> </span><span class="ow">as</span><span class="w"> </span><span class="kt">Integer</span><span class="p">)</span>
<span class="w"> </span><span class="n">intValue</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">intValue</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">2</span>
<span class="k">End</span><span class="w"> </span><span class="k">Sub</span>
</pre></div>
<p>This has a side-effect – modifies the variable passed by reference and could be called for variable <code>v</code> like <code>AddTwo(v)</code>. Giving v is 5 before the call, it will be 7 after.
</p>
<div class="mw-heading mw-heading3"><h3 id="C_and_C++">C and C++</h3></div>
<p>In <a href="C_(programming_language)" title="C (programming language)">C</a> and <a href="C%2B%2B" title="C++">C++</a>, a callable unit is called a <i>function</i>.
A function definition starts with the name of the type of value that it returns or <code>void</code> to indicate that it does not return a value. This is followed by the function name, formal arguments in parentheses, and body lines in braces.
</p><p>In <a href="C%2B%2B" title="C++">C++</a>, a function declared in a <a href="Class_(computer_programming)" title="Class (computer programming)">class</a> (as non-static) is called a <i>member function</i> or <i>method</i>. A function outside of a class can be called a <i>free function</i> to distinguish it from a member function.
<sup id="cite_ref-29" class="reference"><a href="#cite_note-29"><span class="cite-bracket">[</span>29<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">void</span><span class="w"> </span><span class="nf">doSomething</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="cm">/* some code */</span>
<span class="p">}</span>
</pre></div>
<p>This function does not return a value and is always called stand-alone, like <code>doSomething()</code>
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">int</span><span class="w"> </span><span class="nf">giveMeFive</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>This function returns the integer value 5. The call can be stand-alone or in an expression like <code>y = x + giveMeFive()</code>
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">void</span><span class="w"> </span><span class="nf">addTwo</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="o">*</span><span class="n">pi</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>This function has a side-effect – modifies the value passed by address to the input value plus 2. It could be called for variable <code>v</code> as <code>addTwo(&v)</code> where the ampersand (&) tells the compiler to pass the address of a variable. Giving v is 5 before the call, it will be 7 after.
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">void</span><span class="w"> </span><span class="nf">addTwo</span><span class="p">(</span><span class="kt">int</span><span class="o">&</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>This function requires C++ – would not compile as C. It has the same behavior as the preceding example but passes the actual parameter by reference rather than passing its address. A call such as <code>addTwo(v)</code> does not include an ampersand since the compiler handles passing by reference without syntax in the call.
</p>
<div class="mw-heading mw-heading3"><h3 id="PL/I">PL/I</h3></div>
<p>In <a href="PL/I" title="PL/I">PL/I</a> a called procedure may be passed a <i><a href="Data_descriptor" title="Data descriptor">descriptor</a></i> providing information about the argument, such as string lengths and array bounds. This allows the procedure to be more general and eliminates the need for the programmer to pass such information. By default PL/I passes arguments by reference. A (trivial) function to change the sign of each element of a two-dimensional array might look like:
</p>
<pre>change_sign: procedure(array);
declare array(*,*) float;
array = -array;
end change_sign;
</pre>
<p>This could be called with various arrays as follows:
</p>
<pre>/* first array bounds from -5 to +10 and 3 to 9 */
declare array1 (-5:10, 3:9)float;
/* second array bounds from 1 to 16 and 1 to 16 */
declare array2 (16,16) float;
call change_sign(array1);
call change_sign(array2);
</pre>
<div class="mw-heading mw-heading3"><h3 id="Python">Python</h3></div>
<p>In <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, the keyword <code>def</code> denotes the start of a function definition. The statements of the function body follow as indented on subsequent lines and end at the line that is indented the same as the first line or end of file.<sup id="cite_ref-30" class="reference"><a href="#cite_note-30"><span class="cite-bracket">[</span>30<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="k">def</span><span class="w"> </span><span class="nf">format_greeting</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">"Welcome "</span> <span class="o">+</span> <span class="n">name</span>
<span class="k">def</span><span class="w"> </span><span class="nf">greet_martin</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="n">format_greeting</span><span class="p">(</span><span class="s2">"Martin"</span><span class="p">))</span>
</pre></div>
<p>The first function returns greeting text that includes the name passed by the caller. The second function calls the first and is called like <code>greet_martin()</code> to write "Welcome Martin" to the console.
</p>
<div class="mw-heading mw-heading3"><h3 id="Prolog">Prolog</h3></div>
<p>In the procedural interpretation of <a href="Logic_programming" title="Logic programming">logic programs</a>, logical implications behave as goal-reduction procedures. A <a href="Rule-based_system" title="Rule-based system">rule</a> (or <a href="Clause_(logic)" title="Clause (logic)">clause</a>) of the form:
</p>
<dl><dd><code>A :- B</code></dd></dl>
<p>which has the logical reading:
</p>
<dl><dd><code>A if B</code></dd></dl>
<p>behaves as a procedure that reduces goals that <a href="Unification_(computer_science)" title="Unification (computer science)">unify</a> with <code>A</code> to subgoals that are instances of<code>B</code>.
</p><p>Consider, for example, the Prolog program:
</p>
<div class="mw-highlight mw-highlight-lang-prolog mw-content-ltr" dir="ltr"><pre><span class="nf">mother_child</span><span class="p">(</span><span class="s s-Atom">elizabeth</span><span class="p">,</span> <span class="s s-Atom">charles</span><span class="p">).</span>
<span class="nf">father_child</span><span class="p">(</span><span class="s s-Atom">charles</span><span class="p">,</span> <span class="s s-Atom">william</span><span class="p">).</span>
<span class="nf">father_child</span><span class="p">(</span><span class="s s-Atom">charles</span><span class="p">,</span> <span class="s s-Atom">harry</span><span class="p">).</span>
<span class="nf">parent_child</span><span class="p">(</span><span class="nv">X</span><span class="p">,</span> <span class="nv">Y</span><span class="p">)</span> <span class="p">:-</span> <span class="nf">mother_child</span><span class="p">(</span><span class="nv">X</span><span class="p">,</span> <span class="nv">Y</span><span class="p">).</span>
<span class="nf">parent_child</span><span class="p">(</span><span class="nv">X</span><span class="p">,</span> <span class="nv">Y</span><span class="p">)</span> <span class="p">:-</span> <span class="nf">father_child</span><span class="p">(</span><span class="nv">X</span><span class="p">,</span> <span class="nv">Y</span><span class="p">).</span>
</pre></div>
<p>Notice that the motherhood function, <code class="mw-highlight mw-highlight-lang-prolog mw-content-ltr" dir="ltr"><span class="nv">X</span> <span class="o">=</span> <span class="nf">mother</span><span class="p">(</span><span class="nv">Y</span><span class="p">)</span></code> is represented by a relation, as in a <a href="Relational_database" title="Relational database">relational database</a>. However, <i>relations</i> in Prolog <i>function</i> as callable units.
</p><p>For example, the procedure call <code class="mw-highlight mw-highlight-lang-prolog mw-content-ltr" dir="ltr"><span class="s s-Atom">?-</span> <span class="nf">parent_child</span><span class="p">(</span><span class="nv">X</span><span class="p">,</span> <span class="s s-Atom">charles</span><span class="p">)</span></code> produces the output <code class="mw-highlight mw-highlight-lang-prolog mw-content-ltr" dir="ltr"><span class="nv">X</span> <span class="o">=</span> <span class="s s-Atom">elizabeth</span></code>. But the same procedure can be called with other input-output patterns. For example:
</p>
<div class="mw-highlight mw-highlight-lang-prolog mw-content-ltr" dir="ltr"><pre><span class="s s-Atom">?-</span> <span class="nf">parent_child</span><span class="p">(</span><span class="s s-Atom">elizabeth</span><span class="p">,</span> <span class="nv">Y</span><span class="p">).</span>
<span class="nv">Y</span> <span class="o">=</span> <span class="s s-Atom">charles</span><span class="p">.</span>
<span class="s s-Atom">?-</span> <span class="nf">parent_child</span><span class="p">(</span><span class="nv">X</span><span class="p">,</span> <span class="nv">Y</span><span class="p">).</span>
<span class="nv">X</span> <span class="o">=</span> <span class="s s-Atom">elizabeth</span><span class="p">,</span>
<span class="nv">Y</span> <span class="o">=</span> <span class="s s-Atom">charles</span><span class="p">.</span>
<span class="nv">X</span> <span class="o">=</span> <span class="s s-Atom">charles</span><span class="p">,</span>
<span class="nv">Y</span> <span class="o">=</span> <span class="s s-Atom">harry</span><span class="p">.</span>
<span class="nv">X</span> <span class="o">=</span> <span class="s s-Atom">charles</span><span class="p">,</span>
<span class="nv">Y</span> <span class="o">=</span> <span class="s s-Atom">william</span><span class="p">.</span>
<span class="s s-Atom">?-</span> <span class="nf">parent_child</span><span class="p">(</span><span class="s s-Atom">william</span><span class="p">,</span> <span class="s s-Atom">harry</span><span class="p">).</span>
<span class="s s-Atom">no</span><span class="p">.</span>
<span class="s s-Atom">?-</span> <span class="nf">parent_child</span><span class="p">(</span><span class="s s-Atom">elizabeth</span><span class="p">,</span> <span class="s s-Atom">charles</span><span class="p">).</span>
<span class="s s-Atom">yes</span><span class="p">.</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1290876196">
/* start https://en.wikipedia.org/ */
.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .infobox .side-box{font-size:100%}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1237033735">
/* start https://en.wikipedia.org/ */
@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}
/* end https://en.wikipedia.org/ */
</style><div class="side-box side-box-right sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">
/* start https://en.wikipedia.org/ */
.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}
/* end https://en.wikipedia.org/ */
</style>
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">Look up <i><b><a href="https://en.wiktionary.org/wiki/subroutine" class="extiw external" title="wiktionary:subroutine">subroutine </a></b></i> or <i><b><a href="https://en.wiktionary.org/wiki/function" class="extiw external" title="wiktionary:function"> function</a></b></i> in Wiktionary, the free dictionary.</div></div>
</div>
<ul><li><a href="Asynchronous_procedure_call" title="Asynchronous procedure call">Asynchronous procedure call</a>, a subprogram that is called after its parameters are set by other activities</li>
<li><a href="Command%E2%80%93query_separation" title="Command–query separation">Command–query separation</a> (CQS)</li>
<li><a href="Compound_operation_(computer_programming)" class="mw-redirect" title="Compound operation (computer programming)">Compound operation</a></li>
<li><a href="Coroutine" title="Coroutine">Coroutines</a>, subprograms that call each other as if both were the main programs</li>
<li><a href="Evaluation_strategy" title="Evaluation strategy">Evaluation strategy</a></li>
<li><a href="Event_handler" class="mw-redirect" title="Event handler">Event handler</a>, a subprogram that is called in response to an input event or <a href="Interrupt" title="Interrupt">interrupt</a></li>
<li><a href="Function_(mathematics)" title="Function (mathematics)">Function (mathematics)</a></li>
<li><a href="Functional_programming" title="Functional programming">Functional programming</a></li>
<li><a href="Fused_operation" class="mw-redirect" title="Fused operation">Fused operation</a></li>
<li><a href="Generator_(computer_programming)" title="Generator (computer programming)">Generator (computer programming)</a></li>
<li><a href="Intrinsic_function" title="Intrinsic function">Intrinsic function</a></li>
<li><a href="Lambda_function_(computer_programming)" class="mw-redirect" title="Lambda function (computer programming)">Lambda function (computer programming)</a>, a function that is not bound to an identifier</li>
<li><a href="Logic_programming" title="Logic programming">Logic programming</a></li>
<li><a href="Modular_programming" title="Modular programming">Modular programming</a></li>
<li><a href="Operator_overloading" title="Operator overloading">Operator overloading</a></li>
<li><a href="Protected_procedure" title="Protected procedure">Protected procedure</a></li>
<li><a href="Transclusion" title="Transclusion">Transclusion</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://pages.nist.gov/ElectionGlossary/">"Terminology Glossary"</a>. <i>nist.gov</i>. NIST<span class="reference-accessdate">. Retrieved <span class="nowrap">9 February</span> 2024</span>. <q>Callable unit: (Of a software program or logical design) Function, method, operation, subroutine, procedure, or analogous structural unit that appears within a module.</q></cite></span>
</li>
<li id="cite_note-knuth1-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-knuth1_2-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFDonald_E._Knuth1997" class="citation book cs1"><a href="Donald_Knuth" title="Donald Knuth">Donald E. Knuth</a> (1997). <i>The Art of Computer Programming, Volume I: Fundamental Algorithms</i>. Addison-Wesley. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-201-89683-4</bdi>.</cite></span>
</li>
<li id="cite_note-structprog-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-structprog_3-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFO.-J._DahlE._W._DijkstraC._A._R._Hoare1972" class="citation book cs1">O.-J. Dahl; E. W. Dijkstra; C. A. R. Hoare (1972). <i>Structured Programming</i>. Academic Press. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-12-200550-3</bdi>.</cite></span>
</li>
<li id="cite_note-mauchly0-4"><span class="mw-cite-backlink">^ <a href="#cite_ref-mauchly0_4-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-mauchly0_4-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFMauchly1982" class="citation book cs1"><a href="John_Mauchly" title="John Mauchly">Mauchly, J.W.</a> (1982). <a rel="nofollow" class="external text" href="https://archive.org/details/originsofdigital0000rand/page/365">"Preparation of Problems for EDVAC-Type Machines"</a>. In Randell, Brian (ed.). <i>The Origins of Digital Computers</i>. Springer. pp. <span class="nowrap">393–</span>397. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-3-642-61812-3_31">10.1007/978-3-642-61812-3_31</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-3-642-61814-7</bdi>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite id="CITEREFWheeler1952" class="citation conference cs1"><a href="David_Wheeler_(computer_scientist)" title="David Wheeler (computer scientist)">Wheeler, D. J.</a> (1952). <a rel="nofollow" class="external text" href="http://www.laputan.org/pub/papers/wheeler.pdf">"The use of sub-routines in programmes"</a> <span class="cs1-format">(PDF)</span>. <i>Proceedings of the 1952 ACM national meeting (Pittsburgh) on - ACM '52</i>. p. 235. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F609784.609816">10.1145/609784.609816</a></span>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite id="CITEREFWilkesWheelerGill1951" class="citation book cs1">Wilkes, M. V.; Wheeler, D. J.; Gill, S. (1951). <i>Preparation of Programs for an Electronic Digital Computer</i>. Addison-Wesley.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite id="CITEREFDainith2004" class="citation encyclopaedia cs1">Dainith, John (2004). <a rel="nofollow" class="external text" href="http://www.encyclopedia.com/doc/1O11-opensubroutine.html">""open subroutine." A Dictionary of Computing"</a>. <i>Encyclopedia.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">14 January</span> 2013</span>.</cite></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite id="CITEREFTuring1945" class="citation cs2"><a href="Alan_Turing" title="Alan Turing">Turing, Alan M.</a> (1945), <i>Report by Dr. A.M. Turing on proposals for the development of an Automatic Computing Engine (ACE): Submitted to the Executive Committee of the NPL in February 1946</i></cite> reprinted in <cite id="CITEREFCopeland2005" class="citation book cs1"><a href="Jack_Copeland" title="Jack Copeland">Copeland, B. J.</a>, ed. (2005). <span class="id-lock-registration" title="Free registration required"><a rel="nofollow" class="external text" href="https://archive.org/details/alanturingsautom0000unse"><i>Alan Turing's Automatic Computing Engine</i></a></span>. Oxford: Oxford University Press. p. 383. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-19-856593-3</bdi>.</cite></span>
</li>
<li id="cite_note-Turing_1945-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-Turing_1945_9-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFTuring1946" class="citation cs2"><a href="Alan_Mathison_Turing" class="mw-redirect" title="Alan Mathison Turing">Turing, Alan Mathison</a> (19 March 1946) [1945], <i>Proposals for Development in the Mathematics Division of an Automatic Computing Engine (ACE)</i></cite> (NB. Presented on 1946-03-19 before the Executive Committee of the National Physical Laboratory (Great Britain).)</span>
</li>
<li id="cite_note-Carpenter_1977-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-Carpenter_1977_10-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFCarpenterDoran1977" class="citation journal cs1"><a href="Brian_Carpenter_(Internet_engineer)" class="mw-redirect" title="Brian Carpenter (Internet engineer)">Carpenter, Brian Edward</a>; <a href="Robert_William_Doran" class="mw-redirect" title="Robert William Doran">Doran, Robert William</a> (1 January 1977) [October 1975]. <a rel="nofollow" class="external text" href="https://doi.org/10.1093%2Fcomjnl%2F20.3.269">"The other Turing machine"</a>. <i><a href="The_Computer_Journal" title="The Computer Journal">The Computer Journal</a></i>. <b>20</b> (3): <span class="nowrap">269–</span>279. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1093%2Fcomjnl%2F20.3.269">10.1093/comjnl/20.3.269</a></span>.</cite> (11 pages)</span>
</li>
<li id="cite_note-:0-11"><span class="mw-cite-backlink">^ <a href="#cite_ref-:0_11-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-:0_11-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFIsaacson2014" class="citation web cs1">Isaacson, Walter (18 September 2014). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20181212003245/http://fortune.com/2014/09/18/walter-isaacson-the-women-of-eniac/">"Walter Isaacson on the Women of ENIAC"</a>. <i>Fortune</i>. Archived from <a rel="nofollow" class="external text" href="http://fortune.com/2014/09/18/walter-isaacson-the-women-of-eniac/">the original</a> on 12 December 2018<span class="reference-accessdate">. Retrieved <span class="nowrap">14 December</span> 2018</span>.</cite></span>
</li>
<li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><cite id="CITEREFHerman_H._GoldstineJohn_von_Neumann1947" class="citation techreport cs1">Herman H. Goldstine; John von Neumann (1947). <a rel="nofollow" class="external text" href="https://www.ias.edu/sites/default/files/library/pdfs/ecp/planningcodingof0103inst.pdf">"Part II, Volume I-3, Planning and Coding of Problems for an Electronic Computing Instrument"</a> <span class="cs1-format">(PDF)</span>. <i>Report on the Mathematical and Logical aspects of an Electronic Computing Instrument</i> (Technical report).</cite> (see p. 163 of the pdf for the relevant page)</span>
</li>
<li id="cite_note-B5000-21005-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-B5000-21005_13-0">^</a></b></span> <span class="reference-text"><cite class="citation book cs1"><a rel="nofollow" class="external text" href="http://bitsavers.org/pdf/burroughs/LargeSystems/B5000_5500_5700/5000-21005_B5000_operChar_1963.pdf"><i>The Operational Characteristics of the Processors for the Burroughs B5000</i></a> <span class="cs1-format">(PDF)</span>. Revision A. <a href="Burroughs_Corporation" title="Burroughs Corporation">Burroughs Corporation</a>. 1963. 5000-21005<span class="reference-accessdate">. Retrieved <span class="nowrap">8 February</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><cite class="citation book cs1"><a rel="nofollow" class="external text" href="http://bitsavers.org/pdf/dec/pdp6/F-65_PDP-6_Handbook_Aug64.pdf#page=35">"Push-Down Instructions"</a> <span class="cs1-format">(PDF)</span>. <a rel="nofollow" class="external text" href="http://bitsavers.org/pdf/dec/pdp6/F-65_PDP-6_Handbook_Aug64.pdf"><i>Programmed Data Processor 6 - Handbook</i></a> <span class="cs1-format">(PDF)</span>. p. 37<span class="reference-accessdate">. Retrieved <span class="nowrap">8 February</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-Steele-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-Steele_15-0">^</a></b></span> <span class="reference-text">
<a href="Guy_Lewis_Steele_Jr." class="mw-redirect" title="Guy Lewis Steele Jr.">Guy Lewis Steele Jr.</a>
<a href="AI_Memo" title="AI Memo">AI Memo</a> 443.
<a rel="nofollow" class="external text" href="http://dspace.mit.edu/bitstream/handle/1721.1/5753/AIM-443.pdf?sequence=2">'Debunking the "Expensive Procedure Call" Myth; or, Procedure call implementations considered harmful"</a>.
Section "C. Why Procedure Calls Have a Bad Reputation".</span>
</li>
<li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text">
<cite id="CITEREFFrank1983" class="citation book cs1">Frank, Thomas S. (1983). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=YN4mAAAAMAAJ"><i>Introduction to the PDP-11 and Its Assembly Language</i></a>. Prentice-Hall software series. Prentice-Hall. p. 195. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>9780134917047</bdi><span class="reference-accessdate">. Retrieved <span class="nowrap">6 July</span> 2016</span>. <q>We could supply our assembling clerk with copies of the source code for all of our useful subroutines and then when presenting him with a mainline program for assembly, tell him which subroutines will be called in the mainline [...]</q></cite></span>
</li>
<li id="cite_note-ButtlarFarrellNichols1996-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-ButtlarFarrellNichols1996_17-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFButtlarFarrellNichols1996" class="citation book cs1">Buttlar, Dick; Farrell, Jacqueline; Nichols, Bradford (1996). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=vjgEEAAAQBAJ&pg=PA2"><i>PThreads Programming: A POSIX Standard for Better Multiprocessing</i></a>. "O'Reilly Media, Inc.". pp. <span class="nowrap">2–</span>5. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-1-4493-6475-5</bdi>. <a href="OCLC_(identifier)" class="mw-redirect" title="OCLC (identifier)">OCLC</a> <a rel="nofollow" class="external text" href="https://search.worldcat.org/oclc/1036778036">1036778036</a>.</cite></span>
</li>
<li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka13785.html">"ARM Information Center"</a>. Infocenter.arm.com<span class="reference-accessdate">. Retrieved <span class="nowrap">29 September</span> 2013</span>.</cite></span>
</li>
<li id="cite_note-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-19">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.microsoft.com/en-us/cpp/build/stack-usage">"x64 stack usage"</a>. <i>Microsoft Docs</i>. Microsoft<span class="reference-accessdate">. Retrieved <span class="nowrap">5 August</span> 2019</span>.</cite></span>
</li>
<li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://msdn.microsoft.com/en-us/library/67fa79wz%28v=VS.90%29.aspx">"Function Types"</a>. Msdn.microsoft.com<span class="reference-accessdate">. Retrieved <span class="nowrap">29 September</span> 2013</span>.</cite></span>
</li>
<li id="cite_note-clean_code-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-clean_code_21-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFMartin2008" class="citation book cs1">Martin, Robert C. (1 August 2008). <a rel="nofollow" class="external text" href="https://www.oreilly.com/library/view/clean-code-a/9780136083238/"><i>Clean Code: A Handbook of Agile Software Craftsmanship</i></a> (1 ed.). <a href="Pearson_PLC" class="mw-redirect" title="Pearson PLC">Pearson</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>9780132350884</bdi><span class="reference-accessdate">. Retrieved <span class="nowrap">19 May</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-BöckenhauerKommUnger2018-22"><span class="mw-cite-backlink"><b><a href="#cite_ref-BöckenhauerKommUnger2018_22-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFVerhoeff2018" class="citation book cs1">Verhoeff, Tom (2018). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=Z_5sDwAAQBAJ&pg=PA616">"A Master Class on Recursion"</a>. In Böckenhauer, Hans-Joachim; Komm, Dennis; Unger, Walter (eds.). <i>Adventures Between Lower Bounds and Higher Altitudes: Essays Dedicated to Juraj Hromkovič on the Occasion of His 60th Birthday</i>. Springer. p. 616. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-3-319-98355-4</bdi>. <a href="OCLC_(identifier)" class="mw-redirect" title="OCLC (identifier)">OCLC</a> <a rel="nofollow" class="external text" href="https://search.worldcat.org/oclc/1050567095">1050567095</a>.</cite></span>
</li>
<li id="cite_note-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-23">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.ibm.com/docs/en/zos/2.2.0?topic=lf-built-in-functions">"Built-in functions"</a>. <i>ibm.com</i>. 9 March 2017<span class="reference-accessdate">. Retrieved <span class="nowrap">25 December</span> 2023</span>.</cite></span>
</li>
<li id="cite_note-24"><span class="mw-cite-backlink"><b><a href="#cite_ref-24">^</a></b></span> <span class="reference-text"><cite class="citation book cs1"><a rel="nofollow" class="external text" href="https://books.google.com/books?id=d0nhEAAAQBAJ&pg=PA87"><i>Study Material Python</i></a>. April 2023. p. 87<span class="reference-accessdate">. Retrieved <span class="nowrap">25 December</span> 2023</span>.</cite></span>
</li>
<li id="cite_note-25"><span class="mw-cite-backlink"><b><a href="#cite_ref-25">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://smallbasic-publicwebsite.azurewebsites.net/">"Small Basic"</a>. <i>Small Basic</i><span class="reference-accessdate">. Retrieved <span class="nowrap">8 February</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-26"><span class="mw-cite-backlink"><b><a href="#cite_ref-26">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://social.technet.microsoft.com/wiki/contents/articles/16077.small-basic-getting-started-guide-chapter-9-subroutines.aspx">"Small Basic Getting Started Guide: Chapter 9: Subroutines"</a>. Microsoft. 17 January 2024.</cite></span>
</li>
<li id="cite_note-27"><span class="mw-cite-backlink"><b><a href="#cite_ref-27">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/">"Procedures in Visual Basic"</a>. <i>Microsoft Learn</i>. 15 September 2021<span class="reference-accessdate">. Retrieved <span class="nowrap">8 February</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-28"><span class="mw-cite-backlink"><b><a href="#cite_ref-28">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/dim-statement">"Dim statement (Visual Basic)"</a>. <i>Microsoft Learn</i>. 15 September 2021<span class="reference-accessdate">. Retrieved <span class="nowrap">8 February</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-29"><span class="mw-cite-backlink"><b><a href="#cite_ref-29">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://stackoverflow.com/questions/4861914/what-is-the-meaning-of-the-term-free-function-in-c">"what is meant by a free function"</a>.</cite></span>
</li>
<li id="cite_note-30"><span class="mw-cite-backlink"><b><a href="#cite_ref-30">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.python.org/3.9/tutorial/controlflow.html#defining-functions">"4. More Control Flow Tools — Python 3.9.7 documentation"</a>.</cite></span>
</li>
</ol></div></div>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox authority-control" aria-labelledby="Authority_control_databases_frameless&#124;text-top&#124;10px&#124;alt=Edit_this_at_Wikidata&#124;link=https&#58;//www.wikidata.org/wiki/Q190686#identifiers&#124;class=noprint&#124;Edit_this_at_Wikidata719" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Authority_control_databases_frameless&#124;text-top&#124;10px&#124;alt=Edit_this_at_Wikidata&#124;link=https&#58;//www.wikidata.org/wiki/Q190686#identifiers&#124;class=noprint&#124;Edit_this_at_Wikidata719" style="font-size:114%;margin:0 4em">Authority control databases </div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">National</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"><ul><li><span class="uid"><a rel="nofollow" class="external text" href="https://d-nb.info/gnd/4253859-2">Germany</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://id.loc.gov/authorities/sh85129527">United States</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://www.nli.org.il/en/authorities/987007543737405171">Israel</a></span></li></ul></div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Other</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"><ul><li><span class="uid"><a rel="nofollow" class="external text" href="https://lux.collections.yale.edu/view/concept/0364aa7b-d81d-4172-b468-85bb69d70c39">Yale LUX</a></span></li></ul></div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-08-05" href="https://en.wikipedia.org/wiki/?title=Function_(computer_programming)&oldid=1304407670">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>